{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "test=pd.read_csv('stacking_test.csv')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "lfm 1 的mse: 1.3025985204104842\n",
      "lfm 1 的mae: 0.877856799906015\n",
      "lfm 2 的mse: 1.1065605224324786\n",
      "lfm 2 的mae: 0.81694327469465\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "def get_mse(a,b):\n",
    "    return ((a-b)**2).mean()\n",
    "def get_mae(a,b):\n",
    "    return ((np.abs(a-b)).mean())\n",
    "\n",
    "df=test\n",
    "print('lfm 1 的mse:',get_mse(df['rating'],df['pred']))\n",
    "print('lfm 1 的mae:',get_mae(df['rating'],df['pred']))\n",
    "print('lfm 2 的mse:',get_mse(df['rating'],df['pred_2']))\n",
    "print('lfm 2 的mae:',get_mae(df['rating'],df['pred_2']))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "平均融合的mse: 1.0098717671036714\n",
      "平均融合的mae: 0.7866161388617825\n"
     ]
    }
   ],
   "source": [
    "\n",
    "print('平均融合的mse:',get_mse(df['rating'],(df['pred']+df['pred_2'])/2))\n",
    "print('平均融合的mae:',get_mae(df['rating'],(df['pred']+df['pred_2'])/2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
